﻿#region
using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;
using ZhongLangDB;
#endregion

namespace ZHONGLANGWEBUI.ZHONGLANG.SET
{
    public partial class DDL : TT_BasePageList
    {
        protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { pageInit(); dgListDo("查询初次", ""); } }

        #region pageInit
        protected override void pageInit()
        {
            DataTable dtType = DBPark.proGetDT(new SortedList(), "PROTT_SYS_DDLTYPE");
            DDLBind(dtType, "DDLNAME", "DDLNAME", true, ref ddlQDDLTYPE);
            DDLBind(dtType, "DDLNAME", "DDLNAME", false, ref ddlEDDLTYPE);

            DDLBindStr("1$正常,9$停用", true, ref ddlQDDLSTATE);
            DDLBindStr("1$正常,9$停用", false, ref ddlEDDLSTATE);
        }
        #endregion

        #region pageBind 
        protected DataTable proSDListQuery(int iType)
        {
            SortedList SDList = new SortedList();
            SDList["DDLTYPE"] = ddlQDDLTYPE.SelectedValue;
            SDList["DDLNAME"] = txtQDDLNAME.Text;
            SDList["DDLSTATE"] = ddlQDDLSTATE.SelectedValue;
            DataTable dt = pgShow.proQueryData(SDList, "PROTT_SYS_DDLQUERY", iType);
            return dt;
        }

        protected override void pageBind()
        {
            DataTable dt = proSDListQuery(1);
            DataView dv = dt.DefaultView;
            if (ViewState["SortExpression"] != null) { dv.Sort = GetSortDirectiont(ViewState["SortExpression"].ToString(), ViewState["SortDirection"].ToString()); }
            dgList.DataSource = dv; dgList.DataBind();
        }
        #endregion

        #region pageOpt 
        protected override void dgListDo(string strCommandName, string strCommandArgument)
        {
            #region dgBase 
            if (strCommandName == "查询初次") { pgShow.CurrPageIndex = 1; pgShow.CurrPageSize = REQPAGECOUNT; pageBind(); }
            if (strCommandName == "查询") { pageBind(); }
            if (strCommandName == "导出") { proExpData(proSDListQuery(2), dgList); }
            if (strCommandName == "关闭") { tabQuery.Visible = true; tabShow.Visible = true; tabEdit.Visible = false; }
            if (strCommandName == "添加") { lblUpdate.Text = ""; btnSave.CommandArgument = "";  tabQuery.Visible = false; tabShow.Visible = false; tabEdit.Visible = true; }
            #endregion

            #region 修改 
            if (strCommandName == "修改")
            {
                SortedList SDList = new SortedList();
                SDList["KEYID"] = strCommandArgument;
                DataTable dt = DBPark.proGetDT(SDList, "PROTT_SYS_DDLQUERY");
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];

                    DDLBindValue(dr["DDLTYPE"].ToString(), ref ddlEDDLTYPE);
                    txtEDDLCODE.Text = dr["DDLCODE"].ToString();
                    txtEDDLNAME.Text = dr["DDLNAME"].ToString();
                    txtEDDLORDER.Text = dr["DDLORDER"].ToString();
                    DDLBindValue(dr["DDLSTATE"].ToString(), ref ddlEDDLSTATE);

                    lblUpdate.ForeColor = System.Drawing.Color.Blue;
                    lblUpdate.Text = dr["UPDATEMANNAME"].ToString() + "【" + strDateFmtTime(dr["UPDATETIME"].ToString()) + "编辑】";
                    btnSave.CommandArgument = strCommandArgument; tabQuery.Visible = false; tabEdit.Visible = true; tabShow.Visible = false;

                }
                else { jsMessage("参数有误，未找到对应记录！"); }
            }
            #endregion

            #region 保存
            if (strCommandName == "保存")
            {
                SortedList SDList = new SortedList();
                SDList["DDLTYPE"] = ddlEDDLTYPE.SelectedValue;
                SDList["DDLCODE"] = txtEDDLCODE.Text;
                SDList["DDLNAME"] = txtEDDLNAME.Text;
                SDList["DDLORDER"] = txtEDDLORDER.Text;
                SDList["DDLSTATE"] = ddlEDDLSTATE.SelectedValue;
                SDList["KEYID"] = btnSave.CommandArgument; SDList["UPDATEMANID"] = CURREMP.USERID; SDList["UPDATEMANNAME"] = CURREMP.USERNAME;
                string strBack = DBPark.proSetDB(SDList, "PROTT_SYS_DDLSAVE");
                if (strBack != "") { lblUpdate.Text = strBack; lblUpdate.ForeColor = System.Drawing.Color.Red; jsMessage(strBack); }
                else { dgListBaseDo("关闭", ""); }
            }
            #endregion 
        }
        #endregion
         
    }
}